package com.liu.yupao.config;

/**
 * @author lqh
 * @since 2025-08-30 20:40
 */
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 // 开启 Swagger 文档功能
@Profile ({"dev"})  //指定环境加载这个配置
public class Knife4jConfig {

    /**
     * 创建 API 文档的 Docket 对象
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo (apiInfoBuilder ())
                // 选择哪些接口生成文档
                .select()
                // 扫描指定包下的接口（替换为你的实际包路径）
                .apis(RequestHandlerSelectors.basePackage("com.liu.yupao.controller"))
                // 匹配所有路径
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 接口文档信息
     */
    private ApiInfo apiInfoBuilder(){
        return new ApiInfoBuilder()
                .title ("yupao接口文档")
                .description ("yupao-backend")
                .version ("1.0")
                .build ();
    }
}
